package fieldkind

import "reflect"

// 分类
type Kind int

const (
	Unknown Kind = iota
	Class
	Enum
	Map
	Array
	Basic
	Any
)

func ReflectToFieldKind(ftyp reflect.Type) Kind {
	switch ftyp.Kind() {
	case reflect.Interface:
		return Any
	case reflect.Map:
		return Map
	case reflect.Slice:
		fallthrough
	case reflect.Array:
		return Array
	case reflect.Ptr:
		ftyp = ftyp.Elem()
		if ftyp.Kind() == reflect.Struct {
			return Class
		}
	case reflect.Struct:
		return Class
	case reflect.String:
		fallthrough
	case reflect.Bool:
		fallthrough
	case reflect.Int8:
		fallthrough
	case reflect.Int16:
		fallthrough
	case reflect.Int32:
		fallthrough
	case reflect.Int64:
		fallthrough
	case reflect.Int:
		fallthrough
	case reflect.Uint8:
		fallthrough
	case reflect.Uint16:
		fallthrough
	case reflect.Uint32:
		fallthrough
	case reflect.Uint64:
		fallthrough
	case reflect.Uint:
		fallthrough
	case reflect.Float32:
		fallthrough
	case reflect.Float64:
		if ftyp.String() == ftyp.Kind().String() {
			// 基础类型
			return Basic
		} else {
			// 枚举类型
			return Enum
		}

	}
	return Unknown
}
